import type View from '@candy/template/View';
import type HttpRequest from '@candy/framework/http/HttpRequest';
import Controller from '@candy/framework/web/Controller';
import HttpResponse from '@candy/framework/http/HttpResponse';

export default class IndexController extends Controller {
    public override async run(request: HttpRequest): Promise<HttpResponse> {
        const view = this.getView() as View;
        view.enableLayout = false;
        // If cache set to true, when the view file changed, we need to delete the cache file under `runtime` dir
        view.cache = true

        const id = request.getQueryString('id');
        const html = await this.render('index', {
            id,
        });

        return HttpResponse.fromHTML(html);
    }
}
